//
//  BaseView.m
//  事件的产生与传递
//
//  Created by hyl on 16/6/13.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "BaseView.h"

@implementation BaseView

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"%@",[self class]);
}
//- (void)drawRect:(CGRect)rect {
//    NSLog(@"%@ %s",[self class],__func__);
//}

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

    //1.判断这个控件能否响应事件
//    NSLog(@"%i,%i,%i",self.hidden==YES ,self.alpha<0.01 , self.userInteractionEnabled==NO);
    if (self.hidden==YES || self.alpha<0.01 || self.userInteractionEnabled==NO) {
        return nil;
    }
    //2.点是否在这个控件上
    
    if ([self pointInside:point withEvent:event]==NO) {
        return nil;
    }
    //如有子控件，那倒序遍历（即）
    NSInteger counts=self.subviews.count;
    for (NSInteger i=counts-1; i>=0; i--) {
        UIView *childView=self.subviews[i];
        //
        CGPoint childP=[self convertPoint:point toView:childView];
        UIView *view=[childView hitTest:childP withEvent:event];
        if (view) {
            return view;
        }
        
    }
    
    //3.如果都没有合适的，那就返回自身
    return self;
    
    
}


@end
